home *** CD-ROM | disk | FTP | other *** search
- Path: sun001.spd.dsccc.com!spd!jmccarty
- From: jmccarty@spd.dsccc.com (Mike McCarty)
- Newsgroups: comp.lang.c
- Subject: Re: merge algorithm
- Date: 23 Feb 1996 23:50:13 GMT
- Organization: DSC Communications Corporation, Plano, Texas USA
- Message-ID: <4gljrl$auj@sun001.spd.dsccc.com>
- References: <312CEE69.842@onyx.idbsu.edu>
- NNTP-Posting-Host: aplo139.spd.dsccc.com
-
- In article <312CEE69.842@onyx.idbsu.edu>,
- Joe E. Coffland <jcofflan@onyx.idbsu.edu> wrote:
- )I am trying to find an algorithm to merge two sorted arrays containing
- )n elements.
- )ie. A[1] <= A[2]<= ... <= A[m] and A[m+1] <= A[m+2] <= ... <A[n]
- )The algorithm must run in O(n) time and require only a small amount of
- )fixed additional memory regardless of the size of m or n. I have reason
- )to believe that there is such an algorithm but I have only been able to
- )find algorithms that meet the memory restriction but run in at best
- )O(nlogn) and are recursive (which can through some work of course be
- )changed in to an iterative algorithm). If any one can point me to a book
- )or any other source of information on the subject or just get me headed
- )in the right direction it would be greatly appriciated.
- )
- )Thank you in advance,
- )Joe Coffland
- )please mail to: jcofflan@onyx.idbsu.edu
-
-
- Won't a simple exchange algorithm work? Start with pointers into the
- left and right halves. Advance the left pointer until you find an
- element larger than the right pointer data. Exchange the left pointer
- data with the right pointer data. Advance the left pointer etc. When you
- have gone through the entire data set, there is only one output array.
-
- Mike
- ----
- char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
-
- I don't speak for DSC. <- They make me say that.
-